#!/usr/bin/env python3

import sys
import os


def parse_conf(_f, _v):
    _ret = dict()
    with open(_f, 'r') as _fd:
        for _l in _fd.readlines():
            _ll = _l.strip()

            # skip null lines
            if not _ll:
                continue

            # skip comment lines
            if _ll.find("#") == 0:
                continue

            # get kv
            eidx = _ll.find("(")
            if eidx == -1:
                print("WARNNING: not = find in " + _ll);
                continue
            tmpidx = _ll.find("+-")
            if tmpidx == -1:
                tmpidx = _ll.find("\-")
                if tmpidx != -1:
                    tmpidx = tmpidx+2
                    key = _ll[tmpidx:eidx].strip()
            else:
                tmpidx = tmpidx+2
                key = _ll[tmpidx:eidx].strip()
            val = _ll[eidx+1:].strip()

            # use None to descript no val config
            if len(val) == 0:
                val = 'None'

            tmpidx = val.find(_v)
            if tmpidx != -1:
              _ret[key] = val

            break

    return _ret


def comp_conf(_kv1):
    _ret = dict()
    _ret['same'] = dict()
    _ret['diff'] = dict()
    _ret['miss'] = dict()
    miss = 0
    for _k1,_v1 in _kv1.items():
        _tmp = dict()
        _ret['diff'][_k1] = {}
    return _ret


def output(result):
    for _k in ('miss', 'diff', 'same'):
        _v = result.get(_k, {})
        for __k, __v in _v.items():
            print("{:<40}".format(__k))
            break
    
if __name__ == "__main__":
    _f1 = sys.argv[1];
    _v1 = sys.argv[2];

    if os.path.exists(_f1):
      _kv1 = parse_conf(_f1, _v1);
      ret = comp_conf(_kv1)
      output(ret)
